package cm.tl.pms.sys.service.impl;

import cm.tl.pms.sys.entity.SysUserRole;
import cm.tl.pms.sys.mapper.SysUserRoleMapper;
import cm.tl.pms.sys.service.ISysUserRoleService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import com.github.yulichang.base.MPJBaseServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author laker
 * @since 2021-08-11
 */
@Service
public class SysUserRoleServiceImpl extends MPJBaseServiceImpl<SysUserRoleMapper, SysUserRole> implements ISysUserRoleService {

    @Override
    public boolean verifyIsRole(long loginIdAsLong) {
        return SqlHelper.retBool(this.count(Wrappers.lambdaQuery(SysUserRole.class)
                .eq(SysUserRole::getUserId, loginIdAsLong)
        ));
    }

    @Override
    public void addDefaultRole(Long userId) {
        SysUserRole sysUserRole = new SysUserRole();
        sysUserRole.setUserId(userId);
        sysUserRole.setRoleId(2L);
        this.save(sysUserRole);
    }
}
